package ruifight.member.controller;

import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import ruifight.member.model.*;
import ruifight.member.service.AccountRecordService;
import ruifight.member.service.MemberInfoService;
import ruifight.member.service.ShopInfoService;
import ruifight.member.service.UserInfoService;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/interface")
public class AccountRecordController {

	private static final Logger logger = LoggerFactory.getLogger(AccountRecordController.class);

	@Autowired
	public AccountRecordService accountRecordService;
	@Autowired
	MemberInfoService memberInfoService;
	@Autowired
	ShopInfoService shopInfoService;

	/**
	 * 获取交易记录列表
	 * @return
	 */
	@RequestMapping("/getAccountRecordList")
	@ResponseBody
	public Map<String, Object> getAccountRecordList(@RequestBody Map<String, Object> paramMap) {
		Map<String, Object> map = new HashMap<String, Object>();
		String cur_page= paramMap.get("cur_page").toString();
		String page_size= paramMap.get("page_size").toString();
		PageInfo<Map<String, Object>> pageInfo = accountRecordService.getAccountRecordList(Integer.parseInt(cur_page), Integer.parseInt(page_size), paramMap);
		map.put("rows", pageInfo.getList());
		map.put("total", pageInfo.getTotal());
		return map;
	}

	/**
	 * 获取近7天交易量
	 * @return
	 */
	@RequestMapping("/getTradingVolume")
	@ResponseBody
	public Map<String, Object> getTradingVolume(@RequestBody Map<String, Object> paramMap) {
		Map<String, Object> map = new HashMap<String, Object>();
		List<Map<String, Object>> tradingVolumelist = accountRecordService.getTradingVolume();
		List<Map<String, Object>> aturnoverList = accountRecordService.getAturnover();
		Integer memberNumber = memberInfoService.countByExample(new MemberInfoExample());
		Integer shopNumber = shopInfoService.countByExample(new ShopInfoExample());
		Integer accountNumber = accountRecordService.countByExample(new AccountRecordExample());
		map.put("tradingVolume", tradingVolumelist);
		map.put("aturnover", aturnoverList);
		map.put("memberNumber", memberNumber);
		map.put("shopNumber", shopNumber);
		map.put("accountNumber", accountNumber);
		return map;
	}

}
